package com.plian.system.controller.cqzc.info;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import javax.validation.Valid;

import com.plian.system.config.Resubmit;
import org.springframework.web.bind.annotation.*;
import com.plian.system.entity.cqzc.info.InfoRegister;
import com.plian.system.vo.cqzc.info.InfoRegisterVO;
import com.plian.system.wrapper.cqzc.info.InfoRegisterWrapper;
import com.plian.system.service.cqzc.info.IInfoRegisterService;
import com.plian.Tools.base.BaseController;

/**
 * 企业信息登记表 控制器
 *
 * @author ziqiang
 * @since 2025-08-29
 */
@RestController
@AllArgsConstructor
@RequestMapping("api/inforegister")
@Api(value = "企业信息登记表", tags = "企业信息登记表接口")
public class InfoRegisterController extends BaseController {

	private final IInfoRegisterService infoRegisterService;

	private final InfoRegisterWrapper infoRegisterWrapper;
	/**
	 * 详情
	 */
	@PostMapping("/detail")
	@ApiOperation(value = "详情", notes = "传入infoRegister")
	public R<InfoRegisterVO> detail(@RequestBody InfoRegister infoRegister) {
		InfoRegister detail = infoRegisterService.getOne(Condition.getQueryWrapper(infoRegister));
		return R.data(infoRegisterWrapper.entityToVO(detail));
	}

	/**
	 * 分页 企业信息登记表
	 */
	@PostMapping("/list")
	@ApiOperation(value = "分页", notes = "传入infoRegister")
	public ListResult<InfoRegisterVO> list(@RequestBody Query query) {
		List<SearchEntity> entityList = query.getSearch();
		QueryWrapper<InfoRegister> queryWrapper = SearchParamEntiy.getQueryWrapper(
			Condition.getQueryWrapper(new InfoRegister()), entityList
		);
		IPage<InfoRegister> pages = infoRegisterService.page(Condition.getPage(query), queryWrapper);
		List<InfoRegisterVO> infoRegisterVOS = infoRegisterWrapper.entityToVO(pages.getRecords());
		ListResult<InfoRegisterVO> listResult = new ListResult<>(CommonCode.SUCCESS);
		listResult.setList(infoRegisterVOS);
		listResult.setTotal(Long.valueOf(pages.getTotal()).intValue());
		return listResult;
	}

	/**
	 * 新增或修改 企业信息登记表
	 */
	@Resubmit
	@PostMapping("/submit")
	@ApiOperation(value = "新增或修改", notes = "传入infoRegisterVO")
	public R submit(@Valid @RequestBody InfoRegisterVO infoRegisterVO) {
		return infoRegisterService.submit(infoRegisterVO);
	}


	/**
	 * 删除 企业信息登记表
	 */
	@PostMapping("/remove")
	@ApiOperation(value = "删除", notes = "传入 ids")
	public R remove(@RequestBody InfoRegisterVO infoRegisterVO) {
		return R.status(infoRegisterService.removeByIds(infoRegisterVO.getIds()));
	}

}
